package cn.com.pumpkin.aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
/**
 * 
 * 包装器
 */
public class MiddlewareInvocationHandler implements InvocationHandler{
	
	private Aspect aspect;
	
	private Object target;
	
	public MiddlewareInvocationHandler(Aspect aspect,Object target){
		this.aspect = aspect;
		this.target = target;
	}
	
	@Override
	public Object invoke(Object arg0, Method arg1, Object[] arg2)throws Throwable {
		if(aspect.pointCut.matchMethodGateway(arg1)){
			return aspect.enhance.invoke(target, arg1, arg2);
		}
		return arg1.invoke(target, arg2);
	}
}
